$(function(){
	
	var page_type = $('#page_type').val();
	/** 上传控件初始化 */
	fileUpload({
		positionId:'funds_fileupload',
		type: 'detail',
		initType:'ajax',
		ajaxUrl:'attachment/attachments.html',
		ajaxData:{bizId : $('#feedbackId').val(), attaType:'feedBack_funds'},
		atta_name : 'attaFunds',
		upload_table : 'funds_upload_table'
	});
	fileUpload({
		positionId:'result_fileupload',
		type: 'detail',
		initType:'ajax',
		ajaxUrl:'attachment/attachments.html',
		ajaxData:{bizId : $('#feedbackId').val(), attaType:'feedBack_result'},
		atta_name : 'attaResult',
		upload_table : 'result_upload_table'
	});
	
	/** 资金来源 */
	$('#fundsources_label').html(formatTaskFundSources($('#fundSources').val()));
	
	var auditCount = $('#auditCount').val();
	if ('0' == auditCount) {
		$('#last_audit').html('');
		var content = '<tr><td>暂未审核过，无审核记录。</td></tr>';
		$('#last_audit').append(content);
	} else {
		/*** 审核结果格式化 */
		$('#audit_result').html(formateAuditStatus($('#auditStatus').val()));
	}
	
	/** 同意 */
	$('#btnAgree').click(function(){
		$('#status').val('3');
		$('#remark').validatebox({
			required : true,
			tipPosition : 'bottom',
			missingMessage : '审核意见不能为空'
		});
//		console.log($('#remark').val());
		var valid = $('#form').form('validate');
//		console.log(valid);
		if(valid) {
			$("body").mask();
			$('#form').ajaxSubmit({
				url : 'feedback/saveAudit',
				success : function(data) {
					$("body").unmask();
					if (!data.success) {
						$.messager.alert('提醒', data.message,'info');
					} else {
						$.messager.alert('提醒', data.message,'info', function(){
							$('#form').form('clear');
							parent.reSearch();
							parent.closeEasyUiWindow('win');
						});
					}
				}
			});
		}
	});
	
	/** 拒绝 */
	$('#btnRefuse').click(function(){
		$('#status').val('2');
		$('#remark').validatebox({
			required : true,
			tipPosition : 'bottom',
			missingMessage : '审核意见不能为空'
		});
		var valid = $('#form').form('validate');
//		console.log(valid);
		if(valid) {
			$("body").mask();
			$('#form').ajaxSubmit({
				url : 'feedback/saveAudit',
				success : function(data) {
					$("body").unmask();
					if (!data.success) {
						$.messager.alert('提醒', data.message,'info');
					} else {
						$.messager.alert('提醒', data.message,'info', function(){
							$('#form').form('clear');
							parent.reSearch();
							parent.closeEasyUiWindow('win');
						});
					}
				}
			});
		}
	});
	
	/** 取消 */
	$('#btnCancel').click(function(){
		$('#form').form('clear');
		parent.closeEasyUiWindow('win');
	});
});